/**
 * Created by Administrator on 2016/7/4 0004.
 */
var directivesModule = angular.module('directives', []);
directivesModule.directive('noteModel', function($ionicModal) {
  return {
    restrict: 'A',
    scope: {},
    link: function($scope, $element, attr) {
      $ionicModal.fromTemplateUrl('templates/component/noteModel.html', {
        scope: $scope,
        animation: 'slide-in-up'
      }).then(function(modal) {
        $scope.modal = modal;
      });
      $element.on('click', function() {
        $scope.modal.show();
      });
    }
  };
});
directivesModule.directive('settingModel', function($ionicModal, $http,$rootScope) {
  return {
    restrict: 'A',
    scope: {

    },
    link: function($scope, $element, attr) {

      $ionicModal.fromTemplateUrl('templates/component/settingModel.html', {
        scope: $scope,
        animation: 'slide-in-up'
      }).then(function(modal) {
        $scope.settingModel = modal;
      });

      $ionicModal.fromTemplateUrl('templates/component/changePassword.html', {
        scope: $scope,
        animation: 'slide-in-up'
      }).then(function(modal) {
        $scope.changePassModal = modal;
      });

      $scope.requestData = {
        originalPassword: "",
        newPassWord: "",
        surePassword: ""
      };

      $scope.jumpToPassModel = function() {
        $scope.settingModel.hide();
        $scope.changePassModal.show();
      };

      $scope.jumpToSettingModel = function() {
        $scope.changePassModal.hide();
        $scope.settingModel.show();
      };

      $scope.logout = function() {
        $http.get('qss/logout').success(function(res) {
          if (res.success) {
            $scope.settingModel.hide();
            $rootScope.showAlert("退出成功");
            localStorage.removeItem("userData");
            $rootScope.goNewPage("login");
          } else {
            $rootScope.showAlert(res.message);
          }
        });
      };
      
      //修改密码
      $scope.resetPwd = function() {
        if ($scope.requestData.surePassword != $scope.requestData.newPassWord) {
          $rootScope.showAlert("密码不一致");
          return;
        };

        $http.post('qss/user/resetPwd',$scope.requestData).success(function(res) {
          if (res.success) {
            $scope.changePassModal.hide();
            $rootScope.showAlert("修改成功");
            localStorage.removeItem("userData");
            $rootScope.goNewPage("login");
          } else {
            $rootScope.showAlert(res.message);
          }
        });
      };

      $scope.cancle = function() {
        $scope.requestData.originalPassword = "";
        $scope.requestData.newPassWord = "";
        $scope.requestData.surePassword = "";
      };

      $element.on('click', function() {
        $scope.settingModel.show();
      });
    }
  };
});

directivesModule.directive('singleSelect', function() {
  return {
    restrict: 'EA',
    scope: {
      isHas: '=',
      title: "@",
      oneContent: '@',
      twoContent: '@'
    },
    controller: function($scope) {
      $scope.change = function(param) {
        $scope.isHas = param;
      };
    },
    template: function() {
      var html = '<div class="verticalAligMiddle inlineBlock">';
      html += '<span class="verticalAligMiddle" ng-show="title">{{title}}</span>';
      html += '<button class="button button-border-clear-color" ng-class="{\'active\':(isHas == 1)}" ng-click="change(1)">{{oneContent}}</button>';
      html += '<button class="button button-border-clear-color" ng-class="{\'active\':(isHas == 0)}" ng-click="change(0)">{{twoContent}}</button>';
      html += ' </div>';
      return html;
    }
  }
});

directivesModule.directive('tableModule4', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=',
      oneContent: '@',
      twoContent: '@'
    },

    link: function($scope, element, attrs) {

      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };

      $scope.addModuleItem = function() {
        $scope.list.push({
          stake: '',
          result: 0
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule4.html')
  }
});

directivesModule.directive('tableModule401', function() {
  return {
    restrict: 'EA',
    scope: {
      info: "="
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
    },
    templateUrl: ('templates/component/tableModule401.html')
  }
});

directivesModule.directive('tableModuleHeader', function() {
  return {
    restrict: 'EA',
    scope: {
      info: "=",
      subHeader: "@"
    },
    link: function($scope, element, attrs) {
      console.log("link");
    },
    controller: function($scope, $http) {
      console.log("controller");
      $scope.layerList = [{
        id: "1",
        name: "上面层"
      }, {
        id: "2",
        name: "中面层"
      }, {
        id: "3",
        name: "下面层"
      }];
      $scope.workPointList = [{
        id: "1",
        name: "作业点A"
      }, {
        id: "2",
        name: "作业点B"
      }];
    },
    templateUrl: ('templates/component/tableModuleHeader.html')
  }
});

directivesModule.directive('tableModule5', function() {
  return {
    restrict: 'EA',
    scope: {
      content: '='
    },
    link: function($scope, element, attrs) {
      console.log($scope.content);
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
    },
    templateUrl: ('templates/component/tableModule5.html')
  }
});

directivesModule.directive('tableModule502', function() {
  return {
    restrict: 'EA',
    scope: {
      info: "="
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
    },
    templateUrl: ('templates/component/tableModule502.html')
  }
});

directivesModule.directive('tableModule503', function() {
  return {
    restrict: 'EA',
    scope: {
      info: "="
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
    },
    templateUrl: ('templates/component/tableModule503.html')
  }
});

directivesModule.directive('tableModule6', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '='
    },
    link: function($scope, element, attrs) {

      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };

      $scope.addModuleItem = function() {
        $scope.list.push({
          recordTime: "",
          recordTimeDate: null,
          recordResult: 0
        });
      };

      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule6.html')
  }
});

directivesModule.directive('tableModule602', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=list',
    },

    link: function($scope, element, attrs) {

      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };

      $scope.addModuleItem = function() {
        $scope.list.push({
          recordTime: "",
          recordTimeDate: null,
          recordResult: 0
        });
      };

      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule602.html')
  }
});

directivesModule.directive('tableModule7', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=list'
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
      };
      $scope.addModuleItem = function() {
        $scope.list.push({
          transporterNo: "", //运输车号
          mixtureCar: 0, //料车
          tyreIscleaned: 0, //轮胎是否清
          arrivalTemperature: "", //到场温度
          arrivalTime: "", //到场时间
          arrivalTimeDate: null,
          ishitpave: 0, //是否撞击摊铺
          notice: ""
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule7.html')
  }
});

directivesModule.directive('tableModule801', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=list',
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
      $scope.addModuleItem = function() {
        $scope.list.push({
          recordTime: "",
          recordTimeDate: null,
          speed: "",
          times: ""
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule801.html')
  }
});
directivesModule.directive('tableModule802', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=list',
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
      $scope.addModuleItem = function() {
        $scope.list.push({
          recordTime: "",
          recordTimeDate: null,
          recordResult: 0
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule802.html')
  }
});
directivesModule.directive('tableModule803', function() {
  return {
    restrict: 'EA',
    scope: {
      list: '=list',
    },
    link: function($scope, element, attrs) {
      $scope.module = {
        isShow: true,
        title: attrs.title,
        index: attrs.index
      };
      $scope.addModuleItem = function() {
        $scope.list.push({
          recordTime: "",
          recordTimeDate: null,
          recordResult: 0
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule803.html')
  }
});

directivesModule.directive('tableModule9', function() {
  return {
    restrict: 'EA',
    scope: {
      list: "="
    },
    link: function($scope, element, attrs) {

      $scope.addModuleItem = function() {
        $scope.list.push({
          startStakeFirst: "",
          startStakeLast: "",
          endStakeFirst: "",
          endStakeLast: "",
          middlePaveTemperature: "", //靠近中分带摊铺温度
          middleFirstpressTemperature: "", //靠近中分带初压温度
          middleNextpressTemperature: "", //靠近中分带复压温度
          middleEndpressTemperature: "", //靠近中分带终压温度

          outboardPaveTemperature: "", //路肩外侧摊铺温度
          outboardTemperature: "", //路肩外侧初压温度
          outboardNextpressTemperature: "", //路肩外侧复压温度
          outboardEndpressTemperature: "", //路肩外侧终压温度

          jointPaveTemperature: "", //接缝摊铺温度
          jointFirstpressTemperature: "", //接缝初压温度
          jointNextpressTemperature: "", //接缝复压温度
          jointEndpressTemperature: "", //接缝终压温度
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule9.html')
  }
});

directivesModule.directive('tableModule10', function() {
  return {
    restrict: 'EA',
    scope: {
      list: "="
    },
    link: function($scope, element, attrs) {

      $scope.addModuleItem = function() {
        $scope.list.push({
          stakeFirst: "",
          stakeLast: "",
          distance1m: "",
          distance4m: "",
          distance7m: "",
          distance9m: "",
          distance10m: "",
          notice: ""
        });
      };
      $scope.deleteModuleItem = function($index) {
        $scope.list.splice($index, 1);
      };
    },
    templateUrl: ('templates/component/tableModule10.html')
  }
});